﻿''' <summary>
''' This Class will be used to show Tool Tips in the Editor or on the Map or in Game or whenever we need it.
''' </summary>
''' <remarks></remarks>
Public Class ToolTip
    Const AwayFromTarget As Integer = 5
    ''' <summary>
    ''' Single Line at the Top
    ''' </summary>
    ''' <remarks></remarks>
    Dim Headline As String
    ''' <summary>
    ''' The Description for this ToolTip
    ''' </summary>
    ''' <remarks></remarks>
    Dim Description As String()
    ''' <summary>
    ''' The ToolTip refers to this point.
    ''' </summary>
    ''' <remarks></remarks>
    Dim Target As Point
    ''' <summary>
    ''' The Max width for a Tooltip.
    ''' </summary>
    ''' <remarks></remarks>
    Dim MaxWidth As Integer = 120
    ''' <summary>
    ''' The Height of a single Line.
    ''' </summary>
    ''' <remarks></remarks>
    Dim Height As Integer
    ''' <summary>
    ''' The Font used to present the Tooltip.
    ''' </summary>
    ''' <remarks></remarks>
    Dim FontID As Integer
    ''' <summary>
    ''' The longest Text line we have.
    ''' </summary>
    ''' <remarks></remarks>
    Dim CurrentWidth As Integer = 0
    Public Sub New(ByVal Headline As String, ByVal Description As String, ByVal Target As Point, Optional ByVal MaxWidth As Integer = 120)
        Update(Headline, Description, Target, MaxWidth)
    End Sub
    Public Sub Malen()
        'We find out where we need to draw the Tool Tip.
        Dim StartPos As Point = Target + New Point(AwayFromTarget, AwayFromTarget)
        If StartPos.X + CurrentWidth + 4 > DataSettings.BildschirmBreite Then
            StartPos.X = Target.X - CurrentWidth - 4 - AwayFromTarget
        End If
        Dim MaxHeight As Integer = (Description.Length + 1) * Height
        If StartPos.Y + MaxHeight > DataSettings.BildschirmHoehe Then
            StartPos.Y = Target.Y - MaxHeight - AwayFromTarget
        End If
        'Tooltip Background
        Grafikengine.DrawBox(TexturenHalter.GetBoxHintergrund(3), StartPos, New Size(20, 20), New Size(CurrentWidth + 4, MaxHeight + 4), 2, Color.White)
        'Tooltip Headline
        Schriftengine.DrawTextZeile(Headline, StartPos + New Point(2, 2), FontID, Color.Black)
        'Description
        For I = 0 To Description.Length - 1
            Schriftengine.DrawTextZeile(Description(I), StartPos + New Point(2, 2 + Height * (I + 1)), FontID, Color.Black)
        Next
    End Sub
    Public Sub Update(ByVal Headline As String, ByVal Description As String, ByVal Target As Point, Optional ByVal MaxWidth As Integer = 120)
        Me.Headline = Headline
        Me.MaxWidth = MaxWidth
        Me.Target = Target
        FontID = Schriftengine.CreateSchriftart(Schriftengine.Schriftarten.Arial, 8, FontStyle.Regular)
        If Description = "" Then
            Me.Description = New String() {}
        Else
            Me.Description = ObjektText.getStringsZeilenweise(Description, Schriftengine.Fonts(FontID).GetFont, MaxWidth)
        End If
        Height = Schriftengine.Fonts(FontID).GetFont.MeasureString(Schriftengine.MeasureSprite, "T", Microsoft.DirectX.Direct3D.DrawTextFormat.None, Color.Black).Height
        CurrentWidth = Schriftengine.Fonts(FontID).GetFont.MeasureString(Schriftengine.MeasureSprite, Headline, Microsoft.DirectX.Direct3D.DrawTextFormat.None, Color.Black).Width
        For I = 0 To Me.Description.Length - 1
            Dim NewWidth As Integer = Schriftengine.Fonts(FontID).GetFont.MeasureString(Schriftengine.MeasureSprite, Me.Description(I), Microsoft.DirectX.Direct3D.DrawTextFormat.None, Color.Black).Width
            If NewWidth > CurrentWidth Then
                CurrentWidth = NewWidth
            End If
        Next
    End Sub
End Class
